package psn.zjk.common.jxls;

import org.apache.commons.lang3.RandomStringUtils;
import org.jxls.area.Area;
import org.jxls.builder.xls.XlsCommentAreaBuilder;
import org.jxls.common.CellRef;
import org.jxls.common.Context;
import org.jxls.transform.Transformer;
import org.jxls.util.JxlsHelper;
import org.jxls.util.TransformerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class JxlsDemo {

    public static void export(InputStream inputStream, OutputStream outputStream) throws IOException {
        ArrayList<String> strings = new ArrayList<>();
        strings.add(RandomStringUtils.random(4));
        strings.add(RandomStringUtils.random(4));
        strings.add(RandomStringUtils.random(4));
        Context context = new Context();
        context.putVar("datas", strings);

        Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream);
        XlsCommentAreaBuilder xlsCommentAreaBuilder = new XlsCommentAreaBuilder(transformer);
        List<Area> xlsAreaList = xlsCommentAreaBuilder.build();
        for (Area area : xlsAreaList) {
            area.applyAt(new CellRef(area.getStartCellRef().getCellName()), context);
        }
        transformer.write();
    }

}